import { Injectable } from "@angular/core";
import { Mock, Dev } from "../api-path/path";

declare const ENV: {
    environment: any,
    baseUrl: any
};

@Injectable()
export class ConfigService {
    public Env: string;

    // DEFAULT_APIS = {
    //     login: "/micropaas-auth-wuye/oauth/token",
    //     getUser: "assets/mock/user.json",
    //     attachment: "assets/mock/attachment.json",
    //     bill: "assets/mock/bill.json",
    //     device: "assets/mock/device.json",
    //     district: "assets/mock/district.json",
    //     sysUser: "assets/mock/sysUser.json",
    //     workOrder: "assets/mock/workOrder.json"
    // };
    //
    // MOCK_APIS = {
    //     getUser: "assets/mock/user.json",
    //     attachment: "assets/mock/attachment.json",
    //     bill: "assets/mock/bill.json",
    //     device: "assets/mock/device.json",
    //     district: "assets/mock/district.json",
    //     sysUser: "assets/mock/sysUser.json",
    //     workOrder: "assets/mock/workOrder.json",
    //     requestCode: "assets/mock/login.json",
    //     login: "assets/mock/login.json"
    // };

    constructor() {
        this.Env = ENV.environment + "Env";
    }

    public getEndpoint(name: string) {

        const apis = 'mockEnv' === this.Env ? Mock : Dev;

        let path = apis[name];
        if (!path) {
            return Mock[name];
        }

        return ENV.baseUrl + path;
        // return 'http://120.78.83.131/api2' + path;
    }
}
